#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

static void* my_open_file(void* args) {
    const char* filename = args;
    FILE* fp = fopen(filename, "r");
    if(fp == NULL)
        pthread_exit(NULL);

    pthread_cleanup_push(fclose, fp);
    int c;
    while((c = fgetc(fp)) != EOF) {
        fputc(c, stdout);
    }
    pthread_cleanup_pop(1);
}

int main(int argc, char** argv) {
    if(argc < 2) {
        fprintf(stderr, "Read charaters from a file. Usage: %s filename\n", argv[0]);
        exit(1);
    }

    my_open_file(argv[1]);
    exit(0);
}